package com.qfedu.aunt.commons.controller;


import com.qfedu.aunt.commons.pojo.Ad;
import com.qfedu.aunt.commons.result.R;
import com.qfedu.aunt.commons.service.AdService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.annotation.Secured;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * <p>
 * 广告表 前端控制器
 * </p>
 *
 * @author xiaobobo
 * @since 2022-10-26
 */
@RestController
@RequestMapping("/aunt/commons/ad")
@Api(description = "广告模块",tags = "广告模块")
public class AdController {


    @Autowired
    private AdService adService;


    /**
     * 通过广告类型获取广告内容
     * @param adType
     * @return
     */
    @Secured("ROLE_admin")      //表示的是只有admin这个角色才能访问
    @GetMapping("/findAdsByType/{adType}")
    @ApiOperation(value = "通过广告类型查询广告")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "adType",value = "广告类型",dataType = "int",paramType = "path",required = true),
            @ApiImplicitParam(name = "token",value = "用户身份标识",dataType = "string",paramType = "header",required = true)
    })
    public R findAdsByType(@PathVariable("adType") Integer adType) throws Exception {
       List<Ad> adList= adService.findAdsByType(adType);
       return R.ok().setData("adList",adList);
    }

}

